package com.groupbuying.cheetah.pay.service.impl;

import com.groupbuying.cheetah.common.BeanOrMapConvertUtils;
import com.groupbuying.cheetah.pay.dao.PayInfoDao;
import com.groupbuying.cheetah.pay.dao.PayOrderRelDao;
import com.groupbuying.cheetah.pay.domain.PayInfoDO;
import com.groupbuying.cheetah.pay.domain.PayOrderRelDO;
import com.groupbuying.cheetah.pay.service.PayService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PayServiceImpl implements PayService{

    @Autowired
    private PayInfoDao payInfoDao;
    @Autowired
    private PayOrderRelDao payOrderRelDao;

    @Override
    public PayInfoDO get(String id){
        return payInfoDao.get(id);
    }

    @Override
    public List<PayInfoDO> list(Map<String, Object> map){
        return payInfoDao.list(map);
    }

    @Override
    public int count(Map<String, Object> map){
        return payInfoDao.count(map);
    }

    @Override
    public Map<String,String> getPayInfoByOrderId(String orderId) {
        Map<String,String> result = new HashMap<>();
        if (StringUtils.isEmpty(orderId)){
            return null;
        }
        try {
            PayOrderRelDO payOrderRelDO = payOrderRelDao.getByOrderId(orderId);
            PayInfoDO payInfoDO = payInfoDao.get(payOrderRelDO.getId());
            result = BeanOrMapConvertUtils.objectToMapWithoutBlank(payInfoDO);
            result.put("outTradeNo",payOrderRelDO.getOutTradeNo());
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

}
